package arm.attestation.entity;

import arm.common.entity.ABaseEntity;
import arm.dic.entity.DicPeriod;

import javax.persistence.*;
import java.text.SimpleDateFormat;
import java.util.Date;

@Entity
@Table (name= "OBIEKT")

public class Obiekt extends ABaseEntity
{
    private Contract contract;
    private DicPeriod dicPeriod;
    private String name;
      private String adress;
    private Date beginDate;
    private Date endDate;


    @ManyToOne
    @JoinColumn (name= "CONTRACT_ID")
    public Contract getContract() {
        return contract;
    }

    public void setContract(Contract contract) {
        this.contract = contract;
    }


    @ManyToOne
    @JoinColumn (name= "DIC_PERIOD_ID")
    public DicPeriod getDicPeriod() {
        return dicPeriod;
    }

    public void setDicPeriod(DicPeriod dicPeriod) {
        this.dicPeriod = dicPeriod;
    }


   @Basic
    @Column (name= "NAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column (name= "ADRESS")
    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    @Basic
    @Column (name= "BEGIN_DATE")
    public Date getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    @Basic
    @Column (name= "END_DATE")
    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    @Transient
    public String getReportDate()
    {
        StringBuffer result = new StringBuffer("");
        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
        if (getBeginDate() != null)
        {
            result.append(sdf.format(getBeginDate()));
        }
        if (getBeginDate() != null && getEndDate() != null)
        {
            result.append(" - ").append(sdf.format(getEndDate()));
        }
        return result.toString();
    }
}
